package com.demo.shiroDemo07.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class User {
	private Integer id;
	private String username;
	private String password;
	public static final List<User> USERS = new ArrayList<>();
	public static final Map<Integer,User> USER_MAP = new HashMap<>();
	static {
		User user1 = new User(1, "admin", "admin");
		USERS.add(user1);
		USER_MAP.put(user1.getId(), user1);
		User user2 = new User(2, "user", "user");
		USERS.add(user2);
		USER_MAP.put(user2.getId(), user2);
	}
	private static final AtomicInteger idGen = new AtomicInteger(USERS.size());
	
	public static final User addUser(String username, String password){
		User user = new User(username, password);
		USERS.add(user);
		USER_MAP.put(user.getId(), user);
		return user;
	}
	
	public User() {
		super();
	}

	public User(Integer id, String username, String password) {
		this();
		this.id = id;
		this.username = username;
		this.password = password;
	}
	
	public User(String username, String password) {
		this(idGen.incrementAndGet(), username, password);
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
